home *** CD-ROM | disk | FTP | other *** search
- //: C08:ConstTemporary.cpp
- // From Thinking in C++, 2nd Edition
- // Available at http://www.BruceEckel.com
- // (c) Bruce Eckel 1999
- // Copyright notice in Copyright.txt
- // Temporaries are const
-
- class X {};
-
- X f() { return X(); } // Return by value
-
- void g1(X&) {} // Pass by non-const reference
- void g2(const X&) {} // Pass by const reference
-
- int main() {
- // Error: const temporary created by f():
- //! g1(f());
- // OK: g2 takes a const reference:
- g2(f());
- } ///:~
-